<template>
    <div>
        <h1>医生添加页面</h1>
            <table class="table">
                <thead>
                    <tr>
                        <td>姓名:</td>
                        <td><input type="text" v-model="data.dName"></td>
                    </tr>
                    <tr>
                        <td>头像:</td>
                        <td>
                            <input type="file" @change="Photo">
                            <img :src="'https://localhost:7036/'+data.dimg" style="width: 60px; height: 60px;">
                        </td>
                    </tr>
                    <tr>
                        <td>科室:</td>
                        <td><select v-model="data.kid" >
                                <option value="0">请选择</option>
                                <option v-for="a in Xiala1" :value="a.kid">{{a.keName}}</option>
                            </select></td>
                    </tr>
                    <tr>
                        <td>创建日期:</td>
                        <td><input type="date" v-model="data.yTimes"></td>
                    </tr>
                    <tr>
                        <td></td>
                        <td>
                            <input type="button" value="添加" @click="Add">
                            <a href="/DecliceShow">返回</a>
                        </td>
                    </tr>
                </thead>
            </table>
    </div>
</template>

<script setup lang="ts">
import {onMounted, ref} from 'vue'
import axios from 'axios'
import { useRouter } from 'vue-router'
const router = useRouter();



onMounted(()=>{
    Xiala()
})

const Xiala1=ref([{
    "kid": 4,
    "keName": "一类科室",
    "kePeople": "15",
    "keMiaoS": "心血疾病专家",
    "keTimes": "2025-05-19T00:00:00",
    "keLuoji": true
}])

const Xiala=()=>{
    axios.get("/api/KeHome/GetKeshiQuan").then(res=>{
        Xiala1.value=res.data;
    })
}

const data = ref({
    "did": 0,
  "dName": "",
  "dimg": "",
  "kid": 0,
  "yTimes": "2025-05-19T04:38:57.017Z"
})

const Add=()=>{
    if(data.value.dName=="")
{
    alert("姓名不能为空!!!");
    return;
}
    axios.post("/api/Declice/AddDeclice",data.value).then(res=>{
        if(res.data>0)
    {
            alert("添加成功");
            router.push({path:'/DecliceShow'})
    }
    else{
        alert("添加失败");
        return;
    }
    })
}


const Photo=(a:any)=>{
    var f = a.target.files[0];
    var fs = new FormData;
    fs.append("file",f);
    if(f.size>2*1024*1024)
{
    alert("图片不能大于2MB");
    return;
}

    axios.post("/api/ImgPhoto/Photo",fs).then(res=>{
        data.value.dimg=res.data;
    })
}



</script>

<style scoped>

</style>